/**
 * 
 */
package gates;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

/**
 * @author denis
 *
 */
public interface IGate {}

class GateInput extends Observable {
	private Boolean input = null;
	private boolean inputValue;
	private List<Observer> observers = new ArrayList<Observer>();

	public GateInput() {
	}
	
	public GateInput(boolean input) {
		this.inputValue = input;
	}

	public void addObserver(Observer obs) {
		if (observers.contains(obs))
			return;
		observers.add(obs);
//		notifyObserver(obs);
	}
	
	public void deleteObserver(Observer obs) {
		if (observers.contains(obs))
			observers.remove(obs);
	}

	private void notifyObserver(Observer obs) {
		obs.update(this, input);
	}

	public void notifyObservers() {
		for(Observer obs:observers) {
			notifyObserver(obs);
		}
	}
	
	public void setInputValue(boolean inputValue) {
		this.inputValue = inputValue;
	}
	
	public void sendSignal() {
		this.input = inputValue;
		notifyObservers();
	}
}

class GateOutput implements Observer {
	private boolean output;
	
	public GateOutput() {}
	
	public void update(Observable o, Object arg) {
			output = (Boolean) arg;
	}
	
	public boolean getValue() {
		return output;
	}
}

@interface Useless {}

class Battery extends GateInput {
	public Battery() {
		super(true);
//		sendSignal();
	}
}

class Ground extends GateInput {
	public Ground() {
		super(false);
//		sendSignal();
	}
}